<template>
  <view class="content">
    <u-header title="chat" right-icon="cart" />
    <uni-list>
      <uni-list-chat
        v-for="(item, i) in list"
        :key="i"
        :title="item.name"
        :note="item.name"
        showArrow
        :avatar-circle="true"
        :avatar="item.headPic"
        time="2020-02-02 20:20"
        badge-text="12"
        :clickable="true"
        @click="toRoom(item)"
      />
    </uni-list>
  </view>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { friendship } from "@/api/user";
import { onLoad, onShow } from "@dcloudio/uni-app";
import { createRoom, findChatroom ,chatroomList} from "@/api/room";
const list = ref([]);
const roomId = ref("");

onShow(() => {
  getChatGroup()
});
const getChatGroup = async () => {
  list.value = await chatroomList();
};

const toRoom = async (room: Object) => {
  uni.navigateTo({
    url: "/pages/room/index",
    success: (res) => {
      res.eventChannel.emit(
        "dataFromIndex",
        Object.assign({ roomId: room.id })
      );
    },
  });
};

</script>

<style>
.content {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.logo {
  height: 200rpx;
  width: 200rpx;
  margin-top: 200rpx;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 50rpx;
}

.text-area {
  display: flex;
  justify-content: center;
}

.title {
  font-size: 36rpx;
  color: #8f8f94;
}
</style>
